<template>
  <div id="info" style="padding: 10px;">
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      width="50%"
      top="10%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :modal-append-to-body="false"
    >
      <el-form ref="form" :model="submitForm" label-width="100px">
        <el-form-item label="姓名" prop="xm" :rules="[{ required: true, message: '请输入姓名', trigger: 'blur' }]">
          <el-input v-model="submitForm.xm" placeholder="请输入姓名"/>
        </el-form-item>
        <el-form-item label="身份证号" prop="sfzh" :rules="[{ required: true, message: '请输入身份证号', trigger: 'blur' }]">
          <el-input trim v-model.trim="submitForm.sfzh" placeholder="请输入身份证号"/>
        </el-form-item>
        <!-- <el-form-item label="领导类型" prop="leaderType" :rules="[{ required: true, message: '请选择领导类型', trigger: 'blur' }]">
          <el-select v-model="submitForm.leaderType" placeholder="请选择领导类型">
            <el-option v-for="item in leaderTypeOptions" :key="'leaderType_' + item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="领导类型" prop="zwjb">
          <el-select v-model="submitForm.zwjb" placeholder="请选择领导类型" clearable>
            <el-option v-for="item in zwjbList" :key="'person_zwjb_' + item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div style="text-align: center; margin-top: 20px;">
        <el-button type="primary" :loading="btnLoading" @click="submit('form')">确定</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <div v-if="loadingText">{{ loadingText }}</div>
    <el-scrollbar v-else style="height: calc(100vh - 194px)">
      <div v-if="flag === 'user'" style="display: flex; justify-content: space-between; margin-bottom: 6px;">
        <span>
          <el-switch style="padding: 10px 0; margin-right: 10px;" v-model="selectOrEdit" active-text="人员列表详情" inactive-text="人员配置概况"></el-switch>
          <span v-if="selectOrEdit">
            <el-button type="primary" icon="el-icon-arrow-up" :loading="btnLoading" :disabled="!moveUpFlag" @click="moveData(true)">上移</el-button>
            <el-button type="primary" icon="el-icon-arrow-down" :loading="btnLoading" :disabled="!moveDownFlag" @click="moveData(false)">下移</el-button>
          </span>
        </span>
        <span v-if="selectOrEdit">
          <el-popconfirm
            title="确定批量删除所选信息吗？"
            @onConfirm="deleteData()"
            @confirm="deleteData()"
            style="float: right; margin-left: 10px;"
          >
            <el-button slot="reference" type="danger" class="filter-item" icon="el-icon-delete">批量删除</el-button>
          </el-popconfirm>
          <el-button type="success" icon="el-icon-plus" @click="addData()" style="float: right;">新增</el-button>
          <el-upload v-if="type === 2" style="margin: 0 10px; float: right;" class="upload-demo" :before-upload="beforePersonUpload" :on-success="getImportList" :on-error="uploadError" name="file" :show-file-list="false"
            :action="this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/saveImport?jgsyCode='+this.jgsyCode" with-credentials accept="vnd.openxmlformats-officedocument.spreadsheetml.sheet">
            <el-button icon="el-icon-upload2" type="warning" :loading="btnLoading" style="color: white !important;">批量导入</el-button>
          </el-upload>
          <el-button type="primary" icon="el-icon-download" @click="exportPerson(false)" style="float: right;margin-right:10px">导出</el-button>
          <el-button v-if="type === 2" type="success" icon="el-icon-download" @click="exportPerson(true)" style="float: right;margin-right:10px">导出该单位全部人员</el-button>
        </span>
      </div>
      <template v-if="!selectOrEdit">
        <table
          cellspacing="0"
          cellpadding="0"
          class="bztable"
          style="border-right: 1px solid #74A6CC; border-bottom: 1px solid #74A6CC; font-size:var(--size14) !important; font-family: '宋体'"
        >
          <template>
            <tr>
              <th style="width: 20px;"></th>
              <th style="width: 20px;">批准</th>
              <th style="width: 20px;">实有</th>
              <th style="width: 20px;">超缺情况</th>
              <th>人员列表</th>
            </tr>
            <tr>
              <th style="width: 20px;">正职</th>
              <td style="vertical-align: middle;">{{ unitInfo.count1 }}</td>
              <td style="vertical-align: middle;">{{ unitInfo.count11 }}</td>
              <td style="vertical-align: middle;">{{ isEqualHandler(unitInfo.count1, unitInfo.count11) }}</td>
              <td style="text-align: left;">
                <template v-if="personList1.length > 0">
                  <el-tooltip placement="bottom" effect="light">
                  <div slot="content">
                    <el-table
                      :data="personList1"
                      border
                      >
                      <el-table-column align="center" prop="xm" label="姓名" width="100">
                      </el-table-column>
                      <el-table-column align="center" prop="sfzh" label="身份证号" width="200">
                      </el-table-column>
                      <el-table-column align="center" prop="zwjbText" label="领导类型" width="200">
                      </el-table-column>
                    </el-table>
                  </div>
                  <el-button type="text" icon="el-icon-search" />
                </el-tooltip>
                {{ unitInfo.person1 }}
                </template>
              </td>
            </tr>
            <tr>
              <th style="width: 20px;">副职</th>
              <td style="vertical-align: middle;">{{ unitInfo.count2 }}</td>
              <td style="vertical-align: middle;">{{ unitInfo.count22 }}</td>
              <td style="vertical-align: middle;">{{ isEqualHandler(unitInfo.count2, unitInfo.count22) }}</td>
              <td style="text-align: left;">
                <template v-if="personList2.length > 0">
                  <el-tooltip placement="bottom" effect="light">
                    <div slot="content">
                      <el-table
                        :data="personList2"
                        border
                        >
                        <el-table-column align="center" prop="xm" label="姓名" width="100">
                        </el-table-column>
                        <el-table-column align="center" prop="sfzh" label="身份证号" width="200">
                        </el-table-column>
                        <el-table-column align="center" prop="zwjbText" label="领导类型" width="200">
                        </el-table-column>
                      </el-table>
                    </div>
                    <el-button type="text" icon="el-icon-search" />
                  </el-tooltip>
                  {{ unitInfo.person2 }}
                </template>
              </td>
            </tr>
            <tr>
              <th style="width: 20px;">其他人员</th>
              <td style="vertical-align: middle;">{{ unitInfo.count3 }}</td>
              <td style="vertical-align: middle;">{{ unitInfo.count33 }}</td>
              <td style="vertical-align: middle;">{{ isEqualHandler(unitInfo.count3, unitInfo.count33) }}</td>
              <td style="text-align: left;">
                <template v-if="personList3.length > 0">
                  <el-tooltip placement="bottom" effect="light">
                    <div slot="content">
                      <el-table
                        :data="personList3"
                        border
                        >
                        <el-table-column align="center" prop="xm" label="姓名" width="100">
                        </el-table-column>
                        <el-table-column align="center" prop="sfzh" label="身份证号" width="200">
                        </el-table-column>
                        <el-table-column align="center" prop="zwjbText" label="领导类型" width="200">
                        </el-table-column>
                      </el-table>
                    </div>
                    <el-button type="text" icon="el-icon-search" />
                  </el-tooltip>
                  {{ unitInfo.person3 }}
                </template>
              </td>
            </tr>
          </template>
        </table>
      </template>
      <section v-else class="wboxd">
        <el-table
          ref="multipleTable"
          v-loading="listLoading"
          :data="listInfo"
          border
          highlight-current-row
          @selection-change="handleSelectionChange"
        >
          <el-table-column v-if="flag === 'user'" align="center" type="selection" width="50px">
          </el-table-column>
          <el-table-column label="序号" align="center" type="index" width="80px">
          </el-table-column>
          <el-table-column prop="xm" label="姓名" align="center" width="120px">
          </el-table-column>
          <el-table-column prop="sfzh" label="身份证号" align="center" width="160px">
          </el-table-column>
          <el-table-column prop="jgsyName" label="单位" align="center">
            <template slot-scope="scope">
              <div style="text-align: left;">{{ scope.row.jgsyName }}</div>
            </template>
          </el-table-column>
          <el-table-column prop="szjgName" label="内设机构" align="center">
            <template slot-scope="scope">
              <div style="text-align: left;">{{ scope.row.szjgName }}</div>
            </template>
          </el-table-column>
          <el-table-column prop="zwjbText" label="领导" align="center" width="120px">
            <!-- <template slot-scope="scope">
              <span v-if="scope.row.leaderType === 1">正职</span>
              <span v-if="scope.row.leaderType === 2">副职</span>
              <span v-if="scope.row.leaderType === 3">其他</span>
            </template> -->
          </el-table-column>
          <el-table-column v-if="flag === 'user'" label="操作" align="center" width="160px">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="editData(scope.row)">修改</el-button>
              <el-popconfirm
                title="确认要删除该信息吗"
                @onConfirm="deleteData(scope.row.dataId)"
                @confirm="deleteData(scope.row.dataId)"
              >
                <el-button slot="reference" size="small" type="danger">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </section>
      <div v-if="selectOrEdit" class="block">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
export default {
  name: 'DetailPerson',
  props: {
    jgsyCode: '',
    jgsyCodeMinistry: '',
    flag: '',
    type: '',
    dClass: '',
    sourceTable: '',
    leaderCountObj: {
      required: false,
      type: Object,
      default: () => ({})
    }
  },
  watch: {
    jgsyCode: {
      handler () {
        this.loadingText = '正在加载中，请稍后...'
        // if (this.flag === 'user') {
        this.pageNum = 1
        this.getList()
        // }
      },
      immediate: true
    },
    jgsyCodeMinistry: {
      handler () {
        this.loadingText = '正在加载中，请稍后...'
        // if (this.flag === 'user') {
        this.pageNum = 1
        this.getList()
        // }
      },
      immediate: true
    },
    leaderCountObj: {
      handler () {
        this.loadingText = '正在加载中，请稍后...'
        // if (this.flag === 'user') {
        this.pageNum = 1
        this.getList()
        // }
      }
    }
  },
  data () {
    return {
      loadingText: '正在加载中，请稍后...',
      selectOrEdit: false,
      unitInfo: {
        dataId: null,
        count1: 0,
        count11: 0,
        person1: [],
        count2: 0,
        count22: 0,
        person2: [],
        count3: 0,
        count33: 0,
        person3: []
      },
      personList1: [],
      personList2: [],
      personList3: [],
      listLoading: false,
      pageNum: 1,
      pageSize: 10,
      totalnum: null,
      changeSizeFlag: false,
      listInfo: [],
      dialogTitle: '',
      dialogVisible: false,
      submitForm: {
        dataId: null,
        xm: '',
        sfzh: '',
        leaderType: '',
        jgsyCode: '',
        szjg: '',
        zwjb: ''
      },
      zwjbList: [
        {label: '部级正职', value: '111'},
        {label: '部级副职', value: '112'},
        {label: '司局级正职', value: '121'},
        {label: '司局级副职', value: '122'},
        {label: '处级正职', value: '131'},
        {label: '处级副职', value: '132'},
        {label: '科级正职', value: '141'},
        {label: '科级副职', value: '142'},
        {label: '股级正职', value: '151'},
        {label: '股级副职', value: '152'},
        {label: '未定级', value: '153'},
        {label: '其他', value: '154'}
      ],
      leaderTypeOptions: [
        {label: '正职', value: 1},
        {label: '副职', value: 2},
        {label: '其他', value: 3}
      ],
      btnLoading: false,
      multipleSelection: [],
      moveUpFlag: false,
      moveDownFlag: false
    }
  },
  methods: {
    // 获取列表
    getList (selectedId) {
      const para = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      if (this.jgsyCodeMinistry) {
        para.jgsyCode = this.jgsyCodeMinistry
        para.szjg = this.jgsyCode
        para.szjgLikeFlag = false
      } else {
        if (this.type === 2) {
          para.jgsyCode = this.jgsyCode
          para.szjg = this.jgsyCode
        } else if (this.type === 3) {
          para.szjg = this.jgsyCode
          const codeArr = this.jgsyCode.split('-')
          codeArr.pop()
          para.jgsyCode = codeArr.join('-')
        }
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.headcountAPI + `api/tRyJbxx/queryByPage`, para)
        .then(response => {
          if (response.data.success) {
            this.listInfo = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
            if (selectedId) {
              this.$nextTick(() => {
                let newrow = this.listInfo.find(item => item.dataId === selectedId)
                this.$refs.multipleTable.toggleRowSelection(newrow)
              })
            }
            this.personInfoHandler()
            this.listLoading = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
            this.listLoading = false
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    // 处理人员信息
    personInfoHandler () {
      this.unitInfo = {
        dataId: null,
        count1: 0,
        count11: 0,
        person1: [],
        count2: 0,
        count22: 0,
        person2: [],
        count3: 0,
        count33: 0,
        person3: []
      }
      this.unitInfo.dataId = this.leaderCountObj.dataId || null
      if (this.sourceTable === 'office') {
        if (this.dClass === '1e') {
          // 派出机构
          this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.nsldzzbz : -1
          this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.nsldfzbz : -1
          this.getBusHeadcountDetail('dabzst', this.unitInfo.count1, this.unitInfo.count2)
        } else {
          // 机关司局
          this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.nsldzzbz2 : -1
          this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.nsldfzbz2 : -1
          this.getOfficeDetailInfo('oabzSt', this.unitInfo.count1, this.unitInfo.count2)
        }
      } else if (this.sourceTable === 'centre_sy_nsjg') {
        // 事业单位内设机构
        this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.nsldzzbz : -1
        this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.nsldfzbz : -1
        this.getCentreSyNsjgDetailInfo(this.unitInfo.count1, this.unitInfo.count2)
      } else {
        if (this.sourceTable === 'depart') {
          if (this.dClass !== '1e') {
            this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.nsldzzbz : -1
            this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.nsldfzbz : -1
          } else {
            this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.bmldzzbz : -1
            this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.bmldfzbz : -1
          }
          this.getBusHeadcountDetail('dabzst', this.unitInfo.count1, this.unitInfo.count2)
        } else {
          this.unitInfo.count1 = this.leaderCountObj ? this.leaderCountObj.bmldzzbz : -1
          this.unitInfo.count2 = this.leaderCountObj ? this.leaderCountObj.bmldfzbz : -1
          this.getBusHeadcountDetail('sybzhd', this.unitInfo.count1, this.unitInfo.count2)
        }
      }
      this.personList1 = []
      this.personList2 = []
      this.personList3 = []
      const personList = this.listInfo
      if (personList.length > 0) {
        // 正职
        this.personList1 = personList.filter(item => item.leaderType === 1)
        if (this.personList1.length > 0) {
          this.personList1.forEach(item => {
            this.unitInfo.person1.push(item.xm)
          })
          this.unitInfo.count11 = this.personList1.length
          this.unitInfo.person1 = this.unitInfo.person1.join('，')
        }
        // 副职
        this.personList2 = personList.filter(item => item.leaderType === 2)
        if (this.personList2.length > 0) {
          this.personList2.forEach(item => {
            this.unitInfo.person2.push(item.xm)
          })
          this.unitInfo.count22 = this.personList2.length
          this.unitInfo.person2 = this.unitInfo.person2.join('，')
        }
        // 其他
        this.personList3 = personList.filter(item => item.leaderType === 3)
        if (this.personList3.length > 0) {
          this.personList3.forEach(item => {
            this.unitInfo.person3.push(item.xm)
          })
          this.unitInfo.count33 = this.personList3.length
          this.unitInfo.person3 = this.unitInfo.person3.join('，')
        }
      }
      this.loadingText = ''
    },
    // 获取office详情
    getOfficeDetailInfo (flag, count1, count2) {
      this.$http
        .get(this.$http.defaults.headcountAPI + `api/office/getById?jgsyCode=${this.jgsyCode}`)
        .then(response => {
          if (response.data.success === true) {
            const result = response.data.result
            if (result) {
              this.unitInfo.count3 = result[flag] - count1 - count2
            } else {
              this.unitInfo.count3 = 0 - count1 - count2
            }
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    // 获取centreSyNsjg详情
    getCentreSyNsjgDetailInfo (count1, count2) {
      this.$http
        .get(this.$http.defaults.headcountAPI + `api/centreSyNsjg/getById?jgsyCode=${this.jgsyCode}`)
        .then(response => {
          if (response.data.success === true) {
            const result = response.data.result
            result.slnCzbkbzrs = result.slnCzbkbzrs ? result.slnCzbkbzrs : 0
            result.slnJfzlbzrs = result.slnJfzlbzrs ? result.slnJfzlbzrs : 0
            this.unitInfo.count3 = result.slnCzbkbzrs + result.slnJfzlbzrs - count1 - count2
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    // 获取补充表详情
    getBusHeadcountDetail (flag, count1, count2) {
      this.$http
        .get(this.$http.defaults.headcountAPI + `api/busHeadcount/getById?jgsyCode=${this.jgsyCode}`)
        .then(response => {
          if (response.data.success) {
            const result = response.data.result
            if (result) {
              this.unitInfo.count3 = result[flag] - count1 - count2
            } else {
              this.getDetailInfo(flag, count1, count2)
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    // 根据jgsyCode获取单位详情
    getDetailInfo (flag, count1, count2) {
      flag = flag.toUpperCase()
      this.$http
        .get(this.$http.defaults.headcountAPI + `api/busUnit/getDetailInfo?jgsyCode=${this.jgsyCode}`)
        .then(response => {
          if (response.data.success) {
            const result = response.data.result
            if (result) {
              this.unitInfo.count3 = result[flag] - count1 - count2
            } else {
              this.unitInfo.count3 = 0 - count1 - count2
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    // 新增
    addData () {
      this.submitForm.dataId = null
      this.submitForm.xm = ''
      this.submitForm.sfzh = ''
      this.submitForm.leaderType = ''
      this.submitForm.zwjb = ''
      if (this.type === 2) {
        this.submitForm.jgsyCode = this.jgsyCode
        this.submitForm.szjg = null
      } else if (this.type === 3) {
        this.submitForm.szjg = this.jgsyCode
        const codeArr = this.jgsyCode.split('-')
        codeArr.pop()
        this.submitForm.jgsyCode = codeArr.join('-')
      }
      this.dialogTitle = '新增'
      this.dialogVisible = true
    },
    // 编辑
    editData (row) {
      this.submitForm = {...row}
      this.dialogTitle = '编辑'
      this.dialogVisible = true
    },
    // 提交
    submit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const para = {...this.submitForm}
          if (this.jgsyCodeMinistry) {
            para.jgsyCode = this.jgsyCodeMinistry
            para.szjg = para.szjg ? para.szjg : this.jgsyCode
          }
          if (!para.szjg) {
            para.szjg = para.jgsyCode
          }
          this.btnLoading = true
          this.$http
            .post(this.$http.defaults.headcountAPI + 'api/tRyJbxx/save', para)
            .then(response => {
              if (response.data.success === true) {
                this.btnLoading = false
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
                this.dialogVisible = false
                this.getList()
              } else {
                console.log('操作失败:' + response.data.message)
                this.$message({
                  message: '操作失败:' + response.data.message,
                  type: 'error'
                })
                this.btnLoading = false
              }
            })
            .catch(error => {
              console.log(error)
              this.btnLoading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 批量删除
    handleSelectionChange (val) {
      this.multipleSelection = val
      this.moveUpFlag = false
      this.moveDownFlag = false
      if (this.multipleSelection.length === 1) {
        this.moveUpFlag = true
        this.moveDownFlag = true
        if (this.listInfo.findIndex(item => item.dataId === this.multipleSelection[0].dataId) === 0) {
          this.moveUpFlag = false
        }
        if (this.listInfo.findIndex(item => item.dataId === this.multipleSelection[0].dataId) === this.listInfo.length - 1) {
          this.moveDownFlag = false
        }
      }
    },
    // 删除
    deleteData (id) {
      let ids = []
      if (id) {
        ids = [id]
      } else {
        ids = this.multipleSelection.map(item => item.dataId)
      }
      if (ids.length > 0) {
        this.$http
          .post(this.$http.defaults.headcountAPI + 'api/tRyJbxx/remove', { ids: ids })
          .then(response => {
            if (response.data.success === true) {
              this.$message({
                message: '删除成功',
                type: 'success'
              })
              this.getList()
            } else {
              console.log('删除失败:' + response.data.message)
              this.$message({
                message: '删除失败:' + response.data.message,
                type: 'error'
              })
            }
          })
          .catch(error => {
            console.log(error)
          })
      } else {
        this.$message({
          message: '请至少选择一条信息',
          type: 'danger'
        })
      }
    },
    // 上移/下移
    moveData (flag) {
      let para = {
        id: this.multipleSelection[0].dataId,
        up: flag
      }
      this.btnLoading = true
      this.$http.post(this.$http.defaults.headcountAPI + `api/tRyJbxx/updateOrder`, para)
        .then(response => {
          if (response.data.success === true) {
            this.btnLoading = false
            this.getList(this.multipleSelection[0].dataId)
          } else {
            console.log('调整顺序失败:' + response.data.message)
            this.$message({
              message: '调整顺序失败:' + response.data.message,
              type: 'error'
            })
            this.btnLoading = false
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '调整顺序失败:' + error,
            type: 'error'
          })
          this.btnLoading = false
        })
    },
    // 判断超缺情况
    isEqualHandler (para1, para2) {
      if (typeof para1 !== 'number') {
        return ''
      } else if (para1 > para2) {
        return '缺'
      } else if (para1 < para2) {
        return '超'
      } else {
        return '满'
      }
    },
    // 批量导入
    beforePersonUpload (file) {
      const isFormat = file.name.indexOf('.xlsx') > 0
      if (!isFormat) {
        this.$message.error('上传文件只能是 .xlsx 格式!')
        return false
      }
      this.btnLoading = true
      return isFormat
    },
    getImportList (res) {
      this.btnLoading = false
      if (res.success) {
        this.$message({
          message: '导入成功！',
          type: 'success'
        })
        this.getList()
      } else {
        this.$message({
          message: '导入失败:' + res.message,
          type: 'error'
        })
      }
    },
    uploadError (err) {
      this.btnLoading = false
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    // 导出人员
    exportPerson (flag) {
      // console.log('this.jgsyCodeMinistry')
      // console.log(this.jgsyCodeMinistry)
      // console.log('this.jgsyCode')
      // console.log(this.jgsyCode)
      // console.log('flag')
      // console.log(flag)
      if (this.jgsyCodeMinistry) {
        if (flag) {
          window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?szjgLikeFlag=true&jgsyCode=' + this.jgsyCodeMinistry + '&szjg=' + this.jgsyCode)
        } else {
          window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?jgsyCode=' + this.jgsyCodeMinistry + '&szjg=' + this.jgsyCode)
        }
      } else {
        if (this.type === 2) {
          if (flag) {
            window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?szjgLikeFlag=true&jgsyCode=' + this.jgsyCode + '&szjg=' + this.jgsyCode)
          } else {
            window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?jgsyCode=' + this.jgsyCode + '&szjg=' + this.jgsyCode)
          }
        } else {
          const codeArr = this.jgsyCode.split('-')
          codeArr.pop()
          let jgsyCodeParent = codeArr.join('-')
          if (flag) {
            window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?szjgLikeFlag=true&jgsyCode=' + jgsyCodeParent + '&szjg=' + this.jgsyCode)
          } else {
            window.open(this.$http.defaults.baseURL + this.$http.defaults.headcountAPI + 'api/tRyJbxx/getExport?jgsyCode=' + jgsyCodeParent + '&szjg=' + this.jgsyCode)
          }
        }
      }
    }
  }
}
</script>

<style>
.bztable {
  border-top: 1px solid #74A6CC;
  border-left: 1px solid #74A6CC;
  width: 100%;
}
.bztable th,
.bztable td{
  padding: 10px;
  border-right: 1px solid #74A6CC;
  border-bottom: 1px solid #74A6CC;
  vertical-align:top;
  line-height: 150%;
}
.bztable th{
  background:#C0DCF1;
}
</style>
